<?php

namespace ms\models;

use Yii;
use common\models\SysAdminUser;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property integer $id
 * @property string $user_name
 * @property string $password
 */
class User extends SysAdminUser implements \yii\web\IdentityInterface
{  
	/**
	 * 解除模型日志
	 * @see \common\components\ActiveRecord2015::init()
	 */
	public function init(){
		parent::init();
		$this->detachBehavior('log');
	}
    /**
     * @inheritdoc
    */
    public static function findIdentity($id)
    {
        return static::findOne(['id' => $id]);
    }
    
    /**
     * @inheritdoc
     */
    public static function findIdentityByAccessToken($token, $type = null)
    {
        return null;
    }
    
    /**
     * Finds user by username
     *
     * @param  string      $username
     * @return static|null
     */
    public static function findByUsername($username)
    {
        return static::findOne(['user_name'=>$username]);
    }
    
    /**
     * @inheritdoc
     */
    public function getId()
    {
        return $this->id;
    }
    
    /**
     * @inheritdoc
     */
    public function getAuthKey()
    {
        return md5($this->id.'51dh_new2015');
    }
    
    /**
     * @inheritdoc
     */
    public function validateAuthKey($authKey)
    {
        return md5($this->id.'51dh_new2015') == $authKey;
    }
    
    /**
     * Validates password
     *
     * @param  string  $password password to validate
     * @return boolean if password provided is valid for current user
     */
    public function validatePassword($password)
    {
        return $this->password === md5($password);
    }
    
    public function getName() {
    	return $this->user_name;
    }
    
       
}
